package J5_8;

import java.util.Arrays;
import java.util.Scanner;

public class test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String str1 = in.next();
        String str2 = in.next();
        int max = 0;
        for (int i = 0; i <= str2.length() - str1.length(); i++) {
            for (int j = 0, cur = 0; j < str1.length(); j++) {
                if (str1.charAt(j) == str2.charAt(i + j)) {
                    cur++;
                }
                if (j == str1.length() - 1) {
                    max = Math.max(max, cur);
                }
            }
        }
        System.out.println(str1.length() - max);
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            while (min != arr[i]) {
                min *= 2;
                if (min > arr[i]) {
                    System.out.println("NO");
                    return;
                }
            }
        }
        System.out.println("YES");
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int V = in.nextInt(), n = in.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }
        int[][] dp = new int[n+1][V + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= V; j++) {
                dp[i][j] = dp[i-1][j];
                if (arr[i] <= j) {
                    dp[i][j] = Math.max(dp[i-1][j - arr[i]] + arr[i], dp[i-1][j]);
                }
            }
        }
        System.out.println(V - dp[n][V]);
    }
}
